package com.hnevc.trafficdemotest1.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2017/12/30.
 */

public class SpUtils {
    Context mContext;
    SharedPreferences sp;
    public SpUtils(Context context){
        mContext = context;
        sp = mContext.getSharedPreferences("data",Context.MODE_PRIVATE);
    }
    public void setRole(String role){
        if(sp!=null){
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("Role",role);
            editor.commit();
        }
    }
    public String getRole(){
        if(sp!=null){
            String role = sp.getString("Role",null);
            return role;
        }
        return  null;
    }
    public void setUserName(String name){
        if(sp!=null){
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("Name",name);
            editor.commit();
        }
    }
    public String getUserName(){
        if(sp!=null){
            String name = sp.getString("Name",null);
            return name;
        }
        return  null;
    }
    //清理
    public void clear(){
        if(sp!=null){
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("Name",null);
            editor.putString("Role",null);
            editor.commit();
        }
    }

    public boolean getIsRememberPassword() {
        if(sp!=null){
            return sp.getBoolean("RememberPassword",false);
        }
        return false;
    }
    public void setIsRememberPassword(boolean remeberPasword) {
        if(sp!=null){
            SharedPreferences.Editor editer = sp.edit();
            editer.putBoolean("RememberPassword",remeberPasword);
            editer.commit();
        }

    }
    public void setIsAutoLogin(boolean isAutoLogin) {
        if(sp!=null){
            SharedPreferences.Editor editer = sp.edit();
            editer.putBoolean("AutoLogin",isAutoLogin);
            editer.commit();
        }
    }
    public boolean getIsAutoLogin() {
        if(sp!=null){
            return sp.getBoolean("AutoLogin",false);
        }
        return false;
    }

    public String getPassword() {
        if(sp!=null){
            return sp.getString("Password",null);
        }
        return null;
    }
}
